package com.lsg.demo3.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lsg.demo3.entity.Housing;
import com.lsg.demo3.service.IHousingService;
import com.lsg.demo3.service.IRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.lsg.demo3.controller.BaseController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 房源（友范） 前端控制器
 * </p>
 *
 * @author leishuiguang
 * @since 2019-07-14
 */
@RestController
@RequestMapping("/youfan/housing")
public class HousingController extends BaseController {

    @Autowired
    private IHousingService iHousingService;

    @GetMapping("/test")
    @Cacheable(cacheNames = "housingList", key = "123")
    public Map<String, Object> list(Integer current){
        Page<Housing> page = new Page<>();
        page.setCurrent(current);
        page.setSize(10);
//        page.setCurrent(10);
//        page.setSize(100);
//        page.setSearchCount(true);

        IPage<Housing> pages = iHousingService.page(page);
        System.out.println("总记录数total="+pages.getTotal());
        System.out.println("当前页数current="+pages.getCurrent());
        System.out.println("没有条数size="+pages.getSize());
        System.out.println("总页数pages"+pages.getPages());
        System.out.println();
        List<Housing> list = pages.getRecords();
        System.out.println(list);
        Map<String, Object> data = new HashMap<>();
        data.put("data", list);
        return data;
    }
}
